package com.joplus.housekeeper.ui.view.prize;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.joplus.housekeeper.R;
import com.joplus.housekeeper.bean.LotteryBean;
import com.joplus.housekeeper.ui.view.CustomShapeImageView;
import com.joplus.housekeeper.utils.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by jeanboy on 2017/4/20.
 */

public class PanelItemView extends FrameLayout implements ItemView {

    private View overlay;
    private CircleImageView iv;
    private TextView item_tv;

    public PanelItemView(Context context) {
        this(context, null);
    }

    public PanelItemView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public PanelItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        inflate(context, R.layout.view_panel_item, this);
        overlay = findViewById(R.id.overlay);
        iv = (CircleImageView) findViewById(R.id.item_bg);
        item_tv = (TextView) findViewById(R.id.item_tv);
    }


    @Override
    public void setFocus(boolean isFocused) {
        if (overlay != null) {
            overlay.setVisibility(isFocused ? INVISIBLE : VISIBLE);
        }
    }

    LotteryBean.DataBean.AwardListBean bean;

    public LotteryBean.DataBean.AwardListBean getBean() {
        return bean;
    }

    @Override
    public void setBack(LotteryBean.DataBean.AwardListBean bean) {
        this.bean = bean;
        if (bean != null) {
            ImageLoader.getInstance().displayImage(bean.getAwardPicture(), iv);
            StringUtils.setText(item_tv, bean.getName());
            Log.e("item", "setBack: " + bean.toString());
        } else {
            Log.e("item", "setBack: ");
            iv.setImageResource(R.drawable.sad);
            StringUtils.setText(item_tv, "很遗憾");
        }

    }

}
